{extend name="public/original" /}
{block name="title"}编辑权限{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="__JS__/layuiext/formSelects/formSelects-v4.css">
<link rel="stylesheet" type="text/css" href="__CSS__/formSelects.css">
<style type="text/css">
  .layui-input-inline{width: 260px !important;}
</style>
{/block}
{block name="content"}
<div class="layui-form" lay-filter="filter-form-auth" id="form-auth" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item">
          <label class="layui-form-label">姓名</label>
          <div class="layui-input-inline">
              <input  type="text" name="name" lay-verify="name" value="{$info.name}" placeholder="请输入姓名" autocomplete="off" class="layui-input">
          </div>
    </div>

    <div class="layui-form-item">
          <label class="layui-form-label">手机号</label>
          <div class="layui-input-inline">
              <input type="hidden" name="oldphone" value="{$info.phone}">
              <input id="phone" type="text" name="phone" lay-verify="phone" value="{$info.phone}" placeholder="请输入手机号" autocomplete="off" class="layui-input">
          </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <select name="gender" lay-verify="required" lay-filter="switchTest">
                <option value="">请选择</option>
                <option value="1"  {if condition="$info['gender'] == 1 "}  selected {/if} >男</option>
                <option value="2" {if condition="$info['gender'] ==2 "} selected {/if} >女</option>
                <option value="0" {if condition="$info['gender'] ==0 "} selected {/if} >未知</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="hidden" name="id" value="{$info.id}">
        <input type="hidden" name="{:config('this.form_token')}" value="{:token()}" />
        <input type="button" lay-submit lay-filter="submit" id="submit" value="确认">
    </div>

</div>
{/block}
{block name="footjs"}
<script>
  layui.config({
    base: '__JS__/layuiext/' //静态资源所在路径
  }).extend({
    formSelects: 'formSelects/formSelects-v4'
  }).use(['form', 'formSelects'], function(){
    var form = layui.form
    ,formSelects = layui.formSelects;

    formSelects.btns('identity', []);
  
    form.verify({
      name:function(value, item){
        if(!value){
          return '姓名必填';
        }
      },
      phone:function(value, item){
        if(!value){
          return '手机号必填';
        }
        if(value && ! /^1[356789]{1}\d{9}$/.test(value)){
          return '手机号格式不正确';
        }
      }

    })

    form.on('submit(submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  

      $.post("{:route('User/editUser')}", data.field, function(res){
        if(res.code == 1){
          parent.layer.msg('修改成功');
          parent.layui.table.reload('user'); //重载表格
          parent.layer.close(index); //再执行关闭 
        }else{
          layer.msg(res.result, {icon: 5});
        }
      },'json');
    });

  })
</script>
{/block}